﻿using System.Collections.Generic;
using XieCan.AspMVC.Entities;
using XieCan.AspMVC.IService;
using XieCan.AspMVC.Models;

namespace XieCan.AspMVC.Service
{
    public partial class RoleService : IRoleService
    {
        OperateResult<RoleModel> IRoleService.AddRole(RoleModel dto)
        {
            var result = Service.AddRole(dto);
            if (result.Success)
            {
                return OperateResult<RoleModel>.Succeeded(dto);
            }
            return OperateResult<RoleModel>.Failed(result.Error);
        }

        OperateResult<RoleModel> IRoleService.Delete(RoleModel dto)
        {
            var result = Service.Delete(dto);
            if(result.Success)
            {
                return OperateResult<RoleModel>.Succeeded(dto);
            }
            return OperateResult<RoleModel>.Failed(result.Error);
        }

        OperateResult<RoleModel> IRoleService.EditRole(RoleModel dto)
        {
            var result = Service.EditRole(dto);
            if (result.Success)
            {
                var role = result.Data;
                if (role==null)
                    return OperateResult<RoleModel>.Failed("角色不存在");
                return OperateResult<RoleModel>.Succeeded(dto);
            }
            return OperateResult<RoleModel>.Failed(result.Error);
        }

        OperateResult<RoleModel> IRoleService.GetRoleList()
        {
            var result = Service.Select();
            var role = result.Data;
            if (role != null)
            {               
                return OperateResult<RoleModel>.Succeeded((RoleModel)role);
            }
            return OperateResult<RoleModel>.Failed(result.Error);
        }
    }
}
